<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/12/13
  Time: 19:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改</title>
    <script src="/js/jquery-1.8.2.min.js"></script>
    <script src="/js/fileupload.js"></script>
    <script src="/My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" href="/css/css.css">
    <link rel="stylesheet" href="/css/img.css">
</head>
<body>
<form>
    <table>
        <input type="hidden" name="sid" id="sid" value="${param.sid}">
        <tr>
            <td>商品名称</td>
            <td>
                <input type="text" name="sname" id="sname">
            </td>
        </tr>
        <tr>
            <td>商品品牌</td>
            <td>
                <select name="sbrandId" id="bid">
                    <option value="" style="color: #bbbbbb;text-align: center">请选择</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>规格型号</td>
            <td>
                <input type="text" name="sstyle" id="sstyle">
            </td>
        </tr>
        <tr>
            <td>价格</td>
            <td>
                ￥<input type="text" name="sprice" id="sprice">
            </td>
        </tr>
        <tr>
            <td>上架时间</td>
            <td>
                <input type="text" name="stime" id="stime" onclick="WdatePicker()">
            </td>
        </tr>
        <tr>
            <td>商品图片</td>
            <td>
                <div class="photoUpLoad" >
                    <input type="file"   class="photo" name="photo" accept="image/*"><span class="cross">+</span>
                    <img src="" alt="" class="photoEcho">
                </div>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" onclick="upd()" value="修改">
            </td>
        </tr>
    </table>
</form>
</body>
<script>
    $.ajaxSettings.async = false;
    $.ajax({
        url:"brandList",
        type:"post",
        dataType:"json",
        success:function (a) {
            for (var i = 0; i < a.length; i++) {
                var op = "<option value='"+a[i].bid+"' style='text-align: center'>"+a[i].brandName+"</option>";
                $("#bid").append(op);
            }
        }
    })
    var sid = $("#sid").val();
    $.ajax({
        url:"hx",
        type:"post",
        data:{"sid":sid},
        success:function (a) {
            $("#sname").val(a.sname)
            $("#sprice").val(a.sprice)
            $("#stime").val(a.stime)
            $("#sstyle").val(a.sstyle)
            $(".photoEcho").prop("src",a.spic)
            $("[name='sbrandId']").val(a.sbrandId)
        }
    })
    function upd() {
        var formData = new FormData($("form")[0]);
        $.ajax({
            url:"update",
            type:"post",
            data:formData,
            dataType:"json",
            contentType:false,
            processData:false,
            success:function (a) {
                if (a>0){
                    alert("修改成功")
                    location = "list"
                }
            }
        })
    }
</script>
</html>
